﻿using System.Collections.Generic;
using System.Linq;
using Devbridge.IPolice.DataContracts;
using Devbridge.IPolice.DomainModel;

namespace Devbridge.IPolice.RepositoriesMock
{
    public class OffenderRepositoryMock : IOffenderRepository
    {
        private readonly IList<Offender> offenders;

        public OffenderRepositoryMock()
        {
            offenders = new List<Offender>();

            offenders.Add(new Offender { });
            offenders.Add(new Offender { });
            offenders.Add(new Offender { });
        }

        public Offender GetById(int id)
        {
            Offender offender = AllQuery().FirstOrDefault(p => p.Id == id);

            return offender;
        }

        public IQueryable<Offender> AllQuery()
        {
            return offenders.AsQueryable();
        }

        public void Remove(Offender entity)
        {
            offenders.Remove(entity);
        }

        public void Save(Offender entity)
        {
            offenders.Add(entity);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            offenders.Clear();
        }
    }
}